package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Example10_15 {
	
	//Scanner解析文件
	public static void main(String[] args) {
		File file = new File("cost.txt");
		Scanner scanner = null;
		int sum = 0;
		try {
			scanner = new Scanner(file);
			while (scanner.hasNext()) {
				try {
					int price = scanner.nextInt();
					sum += price;
					System.out.println(price);
				} catch (InputMismatchException e) {
					scanner.next();
				}
			}
			System.out.println(sum);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
}
